package cn.itsource.pethome.basic.controller;

import cn.itsource.pethome.org.domain.Shop;
import cn.itsource.pethome.org.service.IShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/activation")
public class ActivationController {

    @Autowired
    private IShopService shopService;

    @GetMapping(value = "/{id}")
    @Transactional
    public String activation(@PathVariable("id") Long id){
        try {
            Shop shop = shopService.loadById(id);
            shop.setState(1);
            shop.getEmployee().setState(1);
            shopService.update(shop);
            return "activationSuccess";
        } catch (Exception e) {
            e.printStackTrace();
            return "activationFail";
        }
    }
}
